﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class UserControl_ucSearch : System.Web.UI.UserControl
{
    TblCustomersDAO customerDAO = new TblCustomersDAO(Global.CONNECTION_STRING);
    
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadCustomerList();
    }
     private void LoadCustomerList()
    {
        try
        {
           
            DataTable dt = customerDAO.GetCustomerList(Global.ConvertToInt(txtCustID.Text),
                txtFirstName.Text, txtLName.Text, txtMobi.Text, "");
             
            grdCustomerList.DataSource = dt;
            grdCustomerList.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE);
        }
    }

     protected void btnSearch_Click(object sender, EventArgs e)
     {
         LoadCustomerList();
     }
     protected void btnClearSearch_Click(object sender, EventArgs e)
     {
         txtFirstName.Text = "";
         txtLName.Text = "";
         txtCustID.Text = "";
         txtMobi.Text = "";
         LoadCustomerList();
     }

     protected void btnClose_Click(object sender, EventArgs e)
     {
         Response.Redirect("Default.aspx");
     }
     protected void grdCustomerList_RowDataBound(object sender, GridViewRowEventArgs e)
     {
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             Label lb_method = (Label)e.Row.Cells[4].FindControl("lbMethod");

             int method = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PreferContactMethod"));
             if (method == 1)
                 lb_method.Text = "Mobile";

             if (method == 2)
                 lb_method.Text = "Email";
             if (method == 3)
                 lb_method.Text = " Home";
             if (method == 4)
                 lb_method.Text = "Work";

         }
     }
     protected void grdCustomerList_PageIndexChanging(object sender, GridViewPageEventArgs e)
     {
         LoadCustomerList();
         grdCustomerList.PageIndex = e.NewPageIndex;
     }
}
